package entity;

import java.lang.String;
import enumeration.ResponseStatusCode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@Data
@NoArgsConstructor
@Builder
public class RpcResponse<T> {
    //请求id
    private String requestId;
    //响应消息
    private T data; //声明一个泛型 消息
    //响应状态码
    private Integer statusCode;
    //响应补充消息
    private String message;

    //快速生成失败信息
    public static <T> RpcResponse failure(ResponseStatusCode code, String requestId){
        RpcResponse<T> rpcResponse = new RpcResponse<T>();
        rpcResponse.setStatusCode(ResponseStatusCode.FAILURE.getCode());
        rpcResponse.setRequestId(requestId);
        rpcResponse.setMessage(code.getMessage());
        return rpcResponse;
    }

    //快速生成成功状态信息
    public static <T> RpcResponse  success(T t,String requestId){
        RpcResponse<T> rpcResponse = new RpcResponse<>();
        rpcResponse.setStatusCode(ResponseStatusCode.SUCCESS.getCode());
        rpcResponse.setData(t);
        rpcResponse.setRequestId(requestId);
        return rpcResponse;
    }
}
